﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.WebUI.Module.Audit
{
    public partial class AddAuditTable : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            string batchID = Request.QueryString["BatchID"];
            string contractID = Request.QueryString["ContractID"];
            txtBatchNo.Text = new Honestysoft.BaseObject.BaseBusinessLogic<Bu_AuditBatch>(Globals.CurrentConnStringName).GetEntity(batchID).BatchNo.ToString();
            txtContractName.Text = new Honestysoft.BaseObject.BaseBusinessLogic<BD_Contract>(Globals.CurrentConnStringName).GetEntity(contractID).Name;
            txtCode.Text = new Honestysoft.Financing.BusinessLogic.Audit(Globals.CurrentConnStringName).GetNextAuditCode(contractID);
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            bool bRet = false;
            try
            {
                bRet = new Honestysoft.Financing.BusinessLogic.Audit(Globals.CurrentConnStringName).CreateAuditTable(UserLoginer.LoginUser.ID, Request.QueryString["BatchID"], Request.QueryString["ContractID"],
                    txtCode.Text.Trim(), Convert.ToDecimal(numCurAmount.Text.Trim()), Convert.ToDecimal(numConPerAmount.Text.Trim()));
                if (bRet)
                {
                    ScriptHelper.Window.AlertClose("新增成功！", true);

                }
                else
                {
                    ScriptHelper.Window.Alert("新增失败！");
                }
            }
            catch (Exception ex)
            {
                Honestysoft.BaseLibrary.ExceptionHandling.ExceptionHelper.ExceptionDistribute(ex, false);
                ScriptHelper.Window.Alert("新增失败！");
            }
        }
    }
}